package sparrowGui.skin
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import sparrowGui.ComponentDraw;
	import sparrowGui.SparrowGUI;

	public class MiniBtnSkin extends TagsBtnSkin
	{
		private const padding:int = 3;
		//图形
		private var shapUp:Shape	= new Shape();
		private var shapDown:Shape	= new Shape();
		private var shapSel:Shape 	= new Shape();
		private var shapOver:Shape	= new Shape();
		
		private var _width:Number;
		private var _height:Number;
		
		public function MiniBtnSkin()
		{
			super();
		}
		override protected function init():void
		{
			super.init();
			
			selectState = new ComponentDraw(SparrowGUI.getIns().btn_up);
			selectState.name = "selectState";
			
			_width = upState.width;
			_height = upState.height;
			drawShape();
		}
		
		private function drawShape():void
		{
			if(upState) upState.addChild(drawLine(shapUp,_width,_height));
			if(downState) downState.addChild(drawLine(shapDown,_width,_height));
			if(selectState) selectState.addChild(drawLine(shapSel,_width,_height,1));
			if(overState) overState.addChild(drawLine(shapOver,_width,_height));
		}
		
		private function drawLine(sp:Shape,w:Number,h:Number,way:int=0,thick:int=1,lineColor:int=0xcccccc):Shape
		{
			sp.graphics.clear();
			sp.graphics.lineStyle(thick,lineColor);
			
			// way==0表示画横线,1表示画框
			if(!way){
				sp.graphics.moveTo(padding,h/2);
				sp.graphics.lineTo((w - padding),h/2);
			}else{
				sp.graphics.moveTo(padding,padding);
				sp.graphics.lineTo((w - padding),padding);
				sp.graphics.lineTo((w - padding),(h - padding));
				sp.graphics.lineTo(padding,(h - padding));
				sp.graphics.lineTo(padding,padding);
			}
			return sp;
		}
		
		override public function set width(w:Number):void
		{
			_width = w;
			super.width = w;
			drawShape();
		}
		
		override public function set height(h:Number):void
		{
			_height = h;
			super.height = h;
			drawShape();
		}
	}
}